package com.example.treeutil.model.layer;

import com.example.treeutil.tree.Node;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.ZoneOffset;
import java.util.Date;
import java.util.List;

/**
 * 2022/12/9
 *
 * @author fengyu
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class WMTS implements Node<String> {
    private String id;

    @ApiModelProperty("服务名称")
    private String name;

    @JsonIgnore
    @ApiModelProperty("所在目录id")
    private String pid;

    @ApiModelProperty("地图服务地址")
    private String url;

    @ApiModelProperty(value = "数据的采集时间", example = "2010-11-20", dataType = "Date")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date mapDate;

    private String matrixSetID;

    public WMTS() {}
    public WMTS(String id, String pid, String name, String url, Date mapDate, String matrixSetID) {
        this.id = id;
        this.pid = pid;
        this.name = name;
        this.url = url;
        this.mapDate = mapDate;
        this.matrixSetID = matrixSetID;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPid() {
        return pid;
    }

    @Override
    public boolean hasParent() {
        return pid != null && pid.length() > 0;
    }

    @Override
    public List<Node> getSubs() {
        return null;
    }

    @Override
    public long getIndex() {
        return mapDate.toInstant().atOffset(ZoneOffset.UTC).toLocalDate().toEpochDay();
    }

    public void setPid(String pid) {
        this.pid = pid;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public Date getMapDate() {
        return mapDate;
    }

    public void setMapDate(Date mapDate) {
        this.mapDate = mapDate;
    }

    public String getMatrixSetID() {
        return matrixSetID;
    }

    public void setMatrixSetID(String matrixSetID) {
        this.matrixSetID = matrixSetID;
    }
}
